package com.mapper;

import com.pojo.DaYi_x;
import com.pojo.QingXu_x;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.Date;
import java.util.List;
@Mapper
public interface DaYiMapper_x {
//    获取回复数量个数
    @Select("select d.*,count(z.id) num from dayi_x d LEFT JOIN zhuti_x z on d.id=z.d_id GROUP BY d.id order by num DESC ")
    @Results(id = "selectAll",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "id",property = "num",one = @One(select = "com.mapper.ZhuTiMapper_x.getNum",fetchType = FetchType.LAZY))
    })
    public List<DaYi_x> selectAll();
//获取最后回复
@Select("select d.*,max(z.time) max,count(z.id) num from dayi_x d LEFT JOIN zhuti_x z on d.id=z.d_id  GROUP BY d.id order by max DESC ")
@Results(id = "selectAll2",value = {
        @Result(id = true,column = "id",property = "id"),
        @Result(column = "id",property = "max",one = @One(select = "com.mapper.ZhuTiMapper_x.getMax",fetchType = FetchType.LAZY)),
        @Result(column = "id",property = "num",one = @One(select = "com.mapper.ZhuTiMapper_x.getNum",fetchType = FetchType.LAZY))
})
public List<DaYi_x> selectAll2();
//    获取最近发表
    @Select("select * from dayi_x  order by time DESC ")
    @Results(id = "selectAll1",value = {
        @Result(id = true,column = "id",property = "id"),
        @Result(column = "id",property = "num",one = @One(select = "com.mapper.ZhuTiMapper_x.getNum",fetchType = FetchType.LAZY))
})
    public List<DaYi_x> selectAll1();
//  获取答疑评论
    @Select("select * from dayi_x where id=#{id}")
    @Results(id = "listAll",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "id",property = "zhuTiXes",many = @Many(select = "com.mapper.ZhuTiMapper_x.getById",fetchType = FetchType.LAZY))
    })
    DaYi_x listAll(Integer id);
//   请求回答
    @Select("select * from dayi_x")
    public List<DaYi_x> selectAll3();


    public List<DaYi_x> select1(@Param("id")Integer id, @Param("user")String user,@Param("time1")String time1,@Param("time2")String time2);
    @Insert("insert into dayi_x (user,title,del,time) values (#{user},#{title},#{del},#{time})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    Integer add(DaYi_x daYiX);
    @Delete("delete from dayi_x where id=#{id};")
    Integer delete(Integer id);

}
